﻿using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace CssAndJsCombiner.UI.WebControls
{
    public class Stylesheet : ClientResourceControl
    {
        public string Media { get; set; }

        protected override string ClientResourceFile
        {
            get { return "css.axd"; }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            string path = AddVersion(Path, ClientResourceType.Css);

            HtmlGenericControl style = new HtmlGenericControl("link");
            style.Attributes.Add("rel", "stylesheet");
            style.Attributes.Add("type", "text/css");
            style.Attributes.Add("href", WebContext.ResolveClientUrlAbsolute(path));
            if (!String.IsNullOrEmpty(Media)) style.Attributes.Add("media", Media.ToLower());

            style.RenderControl(writer);
        }
    }
}
